<template>
  <!-- 产量记录 -->
  <BaseMainSlot :show-tab-box="false">
    <template v-slot:btn-box>
      <ActionBar
        :page-no="42"
        :add-active="addActive"
        :del-active="delActive"
        :edit-active="editActive"
        :cancel-active="cancelActive"
        :save-active="saveActive"
        :has-edit="false"
        :has-save="false"
        :has-cancel="false"
        @add="add"
        @cancel="cancel('formData')"
        @edit="edit"
        @del="del"
        @save="save('formData')"
      />
    </template>
    <template v-slot:search-box>
      <SearchForm
        :form-config="formConfig"
        :form-data="searchlist"
        @search="search"
      />
      <!-- <SearchBox @search="search">
        <div class="common-search-item">
          <div class="label">批次名称:</div>
          <div class="input">
            <el-select v-model="searchlist.batchNo" @change="search" filterable clearable>
              <el-option
                v-for="(item,index) in batchLists"
                :key="index"
                :label="item.batchName"
                :value="item.batchNo"
              />
            </el-select>
          </div>
        </div>
        <div class="common-search-item">
          <div class="label">设施名称:</div>
          <div class="input">
            <el-select v-model="searchlist.facilityNo" @change="search" clearable placeholder="请选择设施">
              <el-option
                v-for="item in facilityLists"
                :key="item.facilityNo"
                :label="item.facilityName"
                :value="item.facilityNo"
              />
            </el-select>
          </div>
        </div>
        <div class="common-search-item">
          <div class="label">产量品级:</div>
          <div class="input">
            <el-select v-model="searchlist.grade" @change="search" clearable placeholder="请选择产量品级">
              <el-option
                v-for="item in gradeList"
                :key="item.id"
                :label="item.name"
                :value="item.name"
              />
            </el-select>
          </div>
        </div>
        <div class="common-search-item">
          <div class="label">承租户:</div>
          <div class="input">
            <el-select v-model="searchlist.lesseeNo" @change="search" filterable clearable>
              <el-option
                v-for="item in lessesArr"
                :key="item.lesseeNo"
                :label="item.lesseeName"
                :value="item.lesseeNo"
              />
            </el-select>
          </div>
        </div>
        <div class="common-search-item">
          <div class="label">记录日期:</div>
          <div class="input">
            <el-date-picker
              v-model="searchlist.date"
              type="datetimerange"
              format="yyyy-MM-dd"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              clearable
              @change="dateChange"
            />
            <span class="dateBtnBox">
              <el-button class="allbtn" @click="dateClear">全部</el-button>
              <span class="dateBtn" :class="{ active: dateActive == 1 }" @click="dateFn(1)">最近一周</span>
              <span class="dateBtn" :class="{ active: dateActive == 2 }" @click="dateFn(2)">最近一个月</span>
              <span class="dateBtn" :class="{ active: dateActive == 3 }" @click="dateFn(3)">最近三个月</span>
            </span>
          </div>
        </div>
      </SearchBox> -->
    </template>
    <template v-slot:table-box>
      <Table
        v-loading="loading"
        :prop-list="tableColumn"
        :list-data="tableData"
        @sortChange="changeTableSort"
        @handleSelectionChange="handleSelectionChange"
      >
        <template v-slot:operation="{ row }">
          <template v-if="!row.index && row.yieldNo">
            <el-button
              v-if="judgePermission(42, 'edit')"
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="handleEdit(row, 'add')"
            >
              <i class="el-icon-plus"></i> 新增
            </el-button>
            <el-button
              v-if="judgePermission(42, 'edit')"
              class="text-btn-cursor"
              type="text"
              size="small"
              @click="handleEdit(row)"
            >
              <i class="el-icon-edit-outline"></i> 修改
            </el-button>
            <el-button
              v-if="judgePermission(42, 'delete')"
              class="text-btn-cursor cursor-delete"
              type="text"
              size="small"
              @click="handleDelete(row)"
            >
              <i class="el-icon-delete"></i> 删除
            </el-button>
          </template>
        </template>
        <template v-slot:batchName="{ row, item }">
          <template v-if="!row.index && row.yieldNo">
            {{
              row.productionBatchBO ? row.productionBatchBO[item.prop] : "——"
            }}
          </template>
        </template>
        <template v-slot:standardName="{ row }">
          <template v-if="!row.index && row.yieldNo">
            {{ row.standard ? row.standard.standardName : "——" }}
          </template>
        </template>
        <template v-slot:plantTypeName="{ row, item }">
          <template v-if="!row.index && row.yieldNo">
            {{ row.standard ? row.standard[item.prop] : "——" }}
          </template>
        </template>
        <template v-slot:yield="{ row }">
          <template v-if="!row.index && row.yieldNo">
            {{ row.yield }}{{ row.unitName }}
          </template>
        </template>
      </Table>
      <Pagination
        :page-size="pageSize"
        :current-page="currentPage"
        :total-size="totalSize"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
    </template>
    <template v-slot:dialog>
      <el-dialog
        :title="dialogTitle + '产量信息'"
        :visible.sync="dialogFormVisible"
        :before-close="cancel"
        width="40%"
      >
        <el-form
          ref="formData"
          label-position="left"
          :model="formData"
          class="el-form"
          :rules="rules"
          :show-message="isshowrulemessage"
        >
          <el-form-item label="设施选择:" prop="facilityNo" class="w50p">
            <el-select
              v-model="formData.facilityNo"
              filterable
              clearable
              placeholder="请选择设施"
              @change="changeFacilityNo"
            >
              <el-option
                v-for="item in facilityLists"
                :key="item.facilityNo"
                :label="item.facilityName"
                :value="item.facilityNo"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="批次名称:" prop="batchList" class="w50p">
            <el-select
              v-model="formData.batchList"
              value-key="value"
              clearable
              filterable
              placeholder="请选择批次"
              @change="getspecification"
            >
              <el-option
                v-for="item in batchList"
                :key="item.batchNo"
                :label="item.batchName"
                :value="{
                  value: item.batchNo,
                  plantVarietyNo: item.varietyNo,
                  farmingTypeNo: item.farmingTypeNo,
                  lesseeNo: item.lesseeNo,
                  lesseeName: item.lesseeName,
                  plantVarietyName: item.varietyName,
                  plantTypeName: item.plantingTypeName,
                  plantTypeNo: item.plantingTypeNo,
                }"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="产量规格:" prop="standardNo" class="w50p">
            <el-select v-model="formData.standardNo" filterable clearable>
              <el-option
                v-for="(item, index) in specificationList"
                :key="index"
                :label="item.standardName"
                :value="item.standardNo"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="产量品级:" prop="grade" class="w50p">
            <el-select v-model="formData.grade" filterable clearable>
              <el-option
                v-for="(item, index) in gradeList"
                :key="index"
                :label="item.name"
                :value="item.id"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="产量:" prop="yield" class="w100p">
            <el-input v-model="formData.yield" clearable style="width: 20%" />
            <el-select
              v-model="formData.unitNo"
              style="width: 20%"
              filterable
              clearable
            >
              <el-option
                v-for="(item, index) in unitList"
                :key="index"
                :label="item.unitName"
                :value="item.unitNo"
              />
            </el-select>
            <img
              v-show="nowChanceStau === 'add'"
              src="@/assets/add1.png"
              style="margin-left: 10px; cursor: pointer"
              @click="otherAdd"
            />
          </el-form-item>
          <div
            v-for="(item, index) in otherNum"
            :key="item"
            style="
              width: 100%;
              display: flex;
              flex-wrap: wrap;
              border: 1px dashed #006e91;
              padding: 10px;
              margin-top: 10px;
            "
          >
            <el-form-item label="产量规格:" style="width: 50%">
              <el-select v-model="otherStandardNos[index]" filterable clearable>
                <el-option
                  v-for="(item, index) in specificationList"
                  :key="index"
                  :label="item.standardName"
                  :value="item.standardNo"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="产量品级:" style="width: 50%">
              <el-select v-model="otherGrades[index]" filterable clearable>
                <el-option
                  v-for="(item, index) in gradeList"
                  :key="index"
                  :label="item.name"
                  :value="item.id"
                />
              </el-select>
            </el-form-item>
            <el-form-item label="产量" style="width: 100%">
              <el-input
                v-model="otherYield[index]"
                clearable
                style="width: 20%"
              />
              <el-select
                v-model="otherUnitNo[index]"
                style="width: 20%"
                filterable
                clearable
              >
                <el-option
                  v-for="(item, index) in unitList"
                  :key="index"
                  :label="item.unitName"
                  :value="item.unitNo"
                />
              </el-select>
            </el-form-item>
          </div>
          <el-form-item label="产出日期:" prop="yieldDate" class="w50p">
            <el-date-picker
              v-model="formData.yieldDate"
              type="date"
              format="yyyy-MM-dd"
              clearable
            />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="zh-button-one" @click="cancel('formData')"
            >取 消</el-button
          >
          <el-button
            class="zh-button-two"
            type="primary"
            @click="save('formData')"
            >保 存</el-button
          >
        </div>
      </el-dialog>
      <el-dialog
        id="tableColumnDialog"
        title="配置列"
        :visible.sync="dialogTableColumnVisible"
      >
        <tableColumn
          v-if="dialogTableColumnVisible"
          ref="tableColumn"
          :table-column="allTableColumn"
          @cancelColumn="cancelColumn"
        />
        <div slot="footer" class="dialog-footer">
          <el-button
            class="zh-button-one"
            @click="dialogTableColumnVisible = false"
          >
            取 消
          </el-button>
          <el-button
            class="zh-button-two"
            type="primary"
            @click="save('formData')"
            >保 存
          </el-button>
        </div>
      </el-dialog>
    </template>
  </BaseMainSlot>
</template>
<script>
import SelectButton from "@/components/selectbutton/index.vue";
import SearchForm from "@/components/searchForm";
import Table from "@/components/table/table.vue";
import ActionBar from "@/components/ActionBar";
import Pagination from "@/components/Pagination";
import nowpagereq from "@/api/digital-production/production-statistics/output-input";
import facreq from "@/api/digital-production/growth-record-management/history-collection-data/index";
// import zhongyangleibie from "@/api/basic-info-manage/category-management/index";
// import zhongyangpizhong from "@/api/basic-info-manage/breed-varieties-management/index";
import divideFacility from "@/api/digital-operation/land-manage/divide-manage/index";
import BaseMainSlot from "@/components/BaseMainSlot/newBaseMainSlot.vue";
import unitreq from "@/api/basic-info-manage/unit-manage/index";
import batcjreq from "@/api/digital-production/production-batch-manage/production-batch-query";
import { mymixin } from "@/utils/mixin";
import { getToken } from "@/utils/auth";
import tenantInfoManage from "@/api/digital-operation/tenant-manage/tenant-info";
import { mapGetters } from "vuex";
export default {
  name: "OutputInput",
  components: {
    SearchForm,
    Table,
    ActionBar,
    Pagination,
    BaseMainSlot,
    SelectButton,
  },
  mixins: [mymixin],
  data() {
    return {
      tableColumn: [
        {
          prop: "batchName",
          label: "批次名称",
          minWidth: "160",
          slotName: "batchName",
        },
        {
          prop: "batchNo",
          label: "批次号",
          minWidth: "160",
          slotName: "batchName",
        },
        { prop: "facilityName", label: "产出设施", minWidth: "120" },
        {
          prop: "plantingTypeName",
          label: "种植类别",
          slotName: "batchName",
          minWidth: "120",
        },
        {
          prop: "varietyName",
          label: "种植品种",
          slotName: "batchName",
          minWidth: "120",
        },
        {
          prop: "lesseeName",
          label: "承租户",
          slotName: "batchName",
          minWidth: "120",
        },
        { prop: "grade", label: "产量品级", minWidth: "120" },
        {
          prop: "standardName",
          label: "产量规格",
          slotName: "standardName",
          minWidth: "120",
        },
        { prop: "yield", label: "产量", slotName: "yield", minWidth: "120" },
        { prop: "yieldDate", label: "产出日期", width: "165" },
        {
          prop: "operation",
          label: "操作",
          slotName: "operation",
          width: "180",
        },
      ],
      formConfig: [
        {
          label: "批次名称",
          prop: "batchNo",
          type: "select",
          options: [], // batchLists
          optionKey: { label: "batchName", value: "batchNo" },
        },
        {
          label: "设施名称",
          prop: "facilityNo",
          type: "select",
          options: [], // facilityLists
          optionKey: { label: "facilityName", value: "facilityNo" },
        },
        {
          label: "产量品级",
          prop: "grade",
          type: "select",
          options: [
            { name: "优", id: 0 },
            { name: "良", id: 1 },
            { name: "差", id: 2 },
          ],
          optionKey: { label: "name", value: "name" },
        },
        {
          label: "选择时间",
          prop: "date",
          type: "daterange",
        },
      ],
      isshowrulemessage: false,
      // 下拉选择框相关
      // 批次选择列表
      batchList: [],
      batchLists: [],
      // 产量规格
      specificationList: [],
      // 产量单位
      unitList: [],
      // 产量品级
      gradeList: [
        { name: "优", id: 0 },
        { name: "良", id: 1 },
        { name: "差", id: 2 },
      ],
      // -- 种养类别相关 --后来者直接换下位置即可
      selectplantlist: [],
      nowplantTypeName: "种养类别",
      planttypeList: [],
      nowvarietyList: [],
      facilityList: [],
      facilityLists: [],
      // --------
      batchfarmtypeid: "", // 跟着批次走的农业类型id
      // 搜索框对象
      searchlist: {
        batchNo: "",
      },
      // 选中的数据项数组
      nowselectedList: [],
      // 当前选中的批次名称
      nowbatchName: "",
      // 当前选中的地块名
      nowfacilityName: "",
      rules: {
        batchList: [
          { required: true, message: "请选择批次", trigger: "change" },
        ],
        facilityNo: [
          { required: true, message: "请选择设施", trigger: "change" },
        ],
        standardNo: [
          {
            required: true,
            message: "请输入产量规格",
            trigger: ["change", "blur"],
          },
        ],
        yieldDate: [
          {
            required: true,
            message: "请选择产出时间",
            trigger: ["change", "blur"],
          },
        ],
        yield: [{ required: true, message: "请输入产出产量", trigger: "blur" }],
        grade: [
          { required: true, message: "请选择产量品级", trigger: "change" },
        ],
        batchSingleNos: [
          {
            required: true,
            message: "编号不能为空",
            trigger: ["change", "blur"],
          },
        ],
      },
      dialogTitle: null,
      dialogFormVisible: false,
      name: "",
      lessesArr: [],
      formData: {
        facilityNo: "",
        batchList: "",
        standardNo: "",
        lesseeName: "",
        unitNo: "",
        yield: "",
        grade: "",
        batchSingleNos: [],
      },
      otherStandardNos: [],
      otherNum: 0,
      otherYield: [],
      otherUnitNo: [],
      otherGrades: [],
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission",
    }),
  },
  watch: {
    nowChanceStau(newvalue) {
      if (newvalue === "add" || newvalue === "") {
        this.formData = {};
      }
      // if (newvalue === "add" || newvalue === "edit" || newvalue === "adds") {
      //   batcjreq
      //     .querybylist({
      //       status: 0,
      //       organizationNo: sessionStorage.organizationNo
      //     })
      //     .then((res) => {
      //       this.batchList = res.data;
      //     });
      // }
      if (newvalue === "") {
        this.isshowrulemessage = false;
      } else {
        this.isshowrulemessage = true;
      }
    },
  },
  created() {
    this.formData = {
      batchList: {},
    };
  },
  mounted() {
    this.getTableDataList();
    this.getselectdatalist();
    this.getfacility();
  },
  methods: {
    otherAdd() {
      this.otherNum++;
      console.log(this.otherYield);
    },
    // 获取下拉框数据
    async getselectdatalist() {
      // 获取产量单位
      unitreq
        .getallBasicunitlist({ unitTypeNo: "1001491726536310784" })
        .then((res) => {
          this.unitList = res.data;
          console.log(res.data, "ress");
        });
      // 获取规模单位列表
      unitreq.getallunitlist().then((res) => {
        this.areaUnitList = res.data;
      });
      // 承租户名称
      const { data: res } = await tenantInfoManage.queryLessesByCondition(
        undefined
      );
      this.lessesArr = res;
      this.getBatch();
      //   // 获取种养类别树状表
      //   zhongyangleibie.getplantingTypeTree().then(
      //     (res) => {
      //       let list = res.data
      //       this.planttypeList = this.filterTreeKey(list)
      //     }
      //   )
    },
    getBatch() {
      // 获取批次
      let params = {
        organizationNo: sessionStorage.organizationNo,
        batchType: "BATCH",
        simpleData: true,
      };
      batcjreq.querybylist(params).then((res) => {
        this.batchLists = res.data;
        this.formConfig[0].options = res.data;
      });
    },
    // 条件查询地块
    getfacilityList() {
      let params = {};
      if (this.formData.batchList) {
        params = {
          batchNo: this.formData.batchList.value,
        };
        facreq.findFacilityByBatchNo(params.batchNo).then((res) => {
          if (res.data) {
            // console.log(res)
            this.facilityList = res.data;
          }
        });
      }
    },
    // TODO:获取设施
    getfacility() {
      divideFacility
        .getFacilityListByConditionAll({
          organizationNo: sessionStorage.organizationNo,
        })
        .then((res) => {
          if (res.data) {
            this.facilityLists = res.data;
            this.formConfig[1].options = res.data;
          }
        });
    },
    // 选择设施
    async changeFacilityNo(e) {
      this.batchList = [];
      this.formData.batchList = "";
      this.formData.standardNo = "";
      this.specificationList = [];
      let params = {
        facilityNo: e,
        batchType: "BATCH",
      };
      let res = await batcjreq.accordPlotGetBatchs(params);
      this.batchList = res.data;
    },
    // 选择批次
    async getspecification(e) {
      // console.log(e); return
      if (e.lesseeName) {
        this.formData.lesseeName = e.lesseeName;
      }
      let id = e.plantVarietyNo;
      if(!e.flag) {
        this.$set(this.formData, "standardNo", "");
      }
      this.specificationList = [];
      this.batchfarmtypeid = e.farmingTypeNo;
      nowpagereq.getspecification(id).then((res) => {
        this.$set(this,'specificationList',res.data)
        // this.specificationList = res.data;
      });
      this.formData = { ...this.formData };
    },
    // 通过种养类别id查品种
    // getpingzghong(e) {
    //   let params = {
    //     plantingTypeId: this.selectplantlist[this.selectplantlist.length - 1]
    //   }
    //   zhongyangpizhong.querybycondition(params).then(
    //     res => {
    //       this.nowvarietyList = res.data
    //     }
    //   )
    // },
    // 通过种养品种id查品种name
    // getvarriety(id) {
    //   let params = {
    //     plantVarietyNo: id
    //   }
    //   zhongyangpizhong.querybycondition(params).then(
    //     res => {
    //       this.nowvarietyList = res.data
    //     }
    //   )
    // },
    // 获取当前拥有类型表格
    getTableDataList() {
      this.loading = true;
      let params = {};
      params = {
        page: this.currentPage,
        size: this.pageSize,
        sortList: this.sortList || [],
        entity: {
          batchType: "BATCH",
          farmingTypeNo: sessionStorage.getItem("farmingTypeNo"),
          ...this.searchlist,
        },
      };
      if (this.searchlist?.date) {
        params.entity.startTime =
          this.searchlist.date && this.dateToFormattwo(this.searchlist.date[0]);
        params.entity.endTime =
          this.searchlist.date && this.dateToFormattwo(this.searchlist.date[1]);
      }
      nowpagereq.getlist(params).then((res) => {
        this.loading = false;
        if (res.code === 0) {
          this.$message.error("表格获取失败");
        }
        let data = res.data.content;
        // 赋值总条数
        this.totalSize = res.data.totalElements;
        // 赋值数组
        this.tableData = data;
        this.tableData.forEach((item) => {
          if (item.productionBatchBO) {
            this.$set(item, "lesseeNo", item.productionBatchBO.lesseeNo);
            this.$set(
              item,
              "completionDate",
              this.dateToFormat(item.productionBatchBO.completionDate)
            );
          }
        });
        this.addblankmet();
        this.resetActionBar();
        this.formData = {
          batchList: {},
        };
      });
    },
    search() {
      this.currentPage = 1;
      // 暂时直接当作表格查询
      this.getTableDataList();
    },
    add() {
      this.addActive = false;
      this.openDialog("add");
      this.formData = {};
    },
    async handleEdit(row, type) {
      // console.log(row,'www'); return
      this.changeFacilityNo(row.facilityNo);
      let listone = { ...row };
      delete listone.facilityNo;
      if (!type) {
        this.formData = listone;
        this.formData.standardNo = row.standardNo;
        console.log(this.formData, "data");
        this.nowfacilityName = row.facilityName;
        if (row.productionBatchBO) {
          this.nowbatchName = row.productionBatchBO.batchName;
          this.formData.batchList = {
            value: row.productionBatchBO.batchNo,
            varietyNo: row.productionBatchBO.varietyNo,
            farmingTypeNo: row.productionBatchBO.farmingTypeNo,
            lesseeNo: row.productionBatchBO.lesseeNo,
            lesseeName: row.productionBatchBO.lesseeName,
            plantVarietyName: row.productionBatchBO.varietyName,
            plantTypeName: row.productionBatchBO.plantingTypeName,
            plantingTypeNo: row.productionBatchBO.plantingTypeNo,
            batchNo: row.productionBatchBO.batchNo,
            standardNo: row.standardNo,
          };
          // this.$set(this.formData, "batchList", {
          //   value: row.productionBatchBO.batchNo,
          //   varietyNo: row.productionBatchBO.plantVarietyNo,
          //   farmingTypeNo: row.productionBatchBO.farmingTypeNo,
          //   lesseeNo: row.productionBatchBO.lesseeNo,
          //   varietyName: row.standard.plantVarietyName,
          //   plantingTypeName: row.standard.plantTypeName,
          //   plantingTypeNo: row.standard.plantTypeNo,
          //   bacthNo: row.productionBatchBO.batchNo
          // })
          this.formData.facilityNo = row.facilityNo;
          this.facilityList = [
            {
              facilityName: row.facilityName,
              facilityNo: row.facilityNo,
            },
          ];
          this.getspecification({
            plantVarietyNo: row.productionBatchBO.varietyNo,
            flag: true
            // plantVarietyNo: row.bacthNo
          });
          this.formData.unitNo = row.unitNo;
          this.formData.unitName = row.unitName;
        }

        if (row.grade === "优") {
          this.formData.grade = 0;
        }
        if (row.grade === "良") {
          this.formData.grade = 1;
        }
        if (row.grade === "差") {
          this.formData.grade = 2;
        }
      } else {
        if (row.productionBatchBO) {
          this.formData.batchList = {
            value: row.productionBatchBO.batchNo,
            varietyNo: row.productionBatchBO.varietyNo,
            farmingTypeNo: row.productionBatchBO.farmingTypeNo,
            lesseeNo: row.productionBatchBO.lesseeNo,
            lesseeName: row.productionBatchBO.lesseeName,
            plantVarietyName: row.productionBatchBO.varietyName,
            plantTypeName: row.productionBatchBO.plantingTypeName,
            plantingTypeNo: row.productionBatchBO.plantingTypeNo,
            bacthNo: row.productionBatchBO.batchNo,
            standardNo: row.standardNo,
            plantTypeNo: row.standard.plantTypeNo,
            plantVarietyNo: row.standard.plantVarietyNo
          };
          this.formData.facilityNo = row.facilityNo;
          this.facilityList = [
            {
              facilityName: row.facilityName,
              facilityNo: row.facilityNo,
            },
          ];
          this.getspecification({
            plantVarietyNo: row.productionBatchBO.varietyNo,
            flag: true
            // plantVarietyNo: row.bacthNo
          });
          this.formData.unitNo = row.unitNo;
          this.formData.unitName = row.unitName;
        }
      }
      this.openDialog(type ? "adds" : "edit");
      // this.$refs.formData.resetFields();
    },
    changePageSize(pageSize) {
      this.pageSize = pageSize;
      this.getTableDataList();
    },
    changeCurrentPage(currentPage) {
      this.currentPage = currentPage;
      this.getTableDataList();
    },
    handleSelectionChange(list) {
      this.nowselectedList = [];
      this.nowselectedList = list.map((item) => {
        return item.yieldNo;
      });
      if (this.nowselectedList && this.nowselectedList.length > 0) {
        this.delActive = true;
      } else this.delActive = false;
    },
    delmessage() {
      if (this.nowChanceStau === "del") {
        nowpagereq.dellist(this.nowselectedList).then((res) => {
          if (res.code === 1) {
            this.getTableDataList();
            this.$message.success("删除成功");
          } else {
            this.$message.error("删除失败");
          }
        });
        this.nowChanceStau = "";
      }
    },
    // 删除
    handleDelete(data) {
      this.$confirm("此操作将永久删除该条数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        customClass: "myClass",
      })
        .then(() => {
          nowpagereq.dellist([data.yieldNo]).then((res) => {
            if (res.code === 1) {
              this.$message.success("删除成功");
              this.getTableDataList();
            } else {
              this.$message.error("删除失败");
            }
          });
        })
        .catch(() => {
          //
          this.$message("取消删除");
        });
    },

    // 取消
    cancel(formData) {
      this.addActive = true;
      this.reset();
      // this.nowChanceStau = 'cancel'
      this.closeDialog();
      this.formData = {};
      if (formData) {
        // console.log(formData)
        this.$refs.formData.resetFields();
      }
      this.batchList = [];
    },
    reset() {
      this.otherNum = 0;
      this.otherStandardNos = [];
      this.otherYield = [];
      this.otherUnitNo = [];
      this.otherGrades = [];
    },
    save(formData) {
      this.$refs[formData].validate((valid) => {
        if (valid) {
          if (this.nowChanceStau === "add" || this.nowChanceStau === "adds") {
            // this.getvarriety(this.formData.plantVarietyNo)
            let addparams = {
              ...this.formData,
              organizationNo: getToken("organizationNo"),
              batchNo: this.formData.batchList.value,
              plantTypeNo: this.formData.batchList.plantTypeNo,
              plantVarietyNo: this.formData.batchList.plantVarietyNo,
              plantTypeName: this.formData.batchList.plantTypeName,
              plantVarietyName: this.formData.batchList.plantVarietyName,
              farmingTypeNo: this.batchfarmtypeid, // 这是跟着批次农业类型id
            };
            if (addparams.facilityNo) {
              this.facilityList.forEach((zzfac) => {
                if (zzfac.facilityNo === addparams.facilityNo) {
                  addparams.facilityName = zzfac.facilityName;
                }
              });
            }
            if (addparams.unitNo) {
              this.unitList.forEach((unitem) => {
                if (unitem.unitNo === addparams.unitNo) {
                  addparams.unitName = unitem.unitName;
                }
              });
            }
            addparams.yieldDate = this.dateToFormat(addparams.yieldDate);
            if (addparams.grade || addparams.grade === 0) {
              addparams.grade = this.gradeList[addparams.grade].name;
            }
            if(this.nowChanceStau === "adds") {
              addparams.lesseeName = addparams.batchList.lesseeName,
              addparams.plantTypeNo = addparams.batchList.plantTypeNo,
              addparams.farmingTypeNo = addparams.batchList.farmingTypeNo
            }
            delete addparams.batchList;
            let arr = [];
            arr.push(addparams);
            // console.log(addparams); return
            let params = { ...addparams };
            this.otherStandardNos.forEach((el, index) => {
              params.standardNo = el;
              if (this.otherGrades[index] === 0) {
                params.grade = "优";
              } else if (this.otherGrades[index] === 1) {
                params.grade = "良";
              } else {
                params.grade = "差";
              }
              params.yield = this.otherYield[index];
              params.unitNo = this.otherUnitNo[index];
              arr.push(params);
            });
            // console.log(arr); return
            batcjreq.addList(arr).then((res) => {
              if (res.code === 1) {
                this.getTableDataList();
                this.$message.success("添加成功");
                this.closeDialog();
                this.reset();
                this.$refs[formData].resetFields();
              } else {
                this.$message.error("添加失败");
              }
            });
          } else if (this.nowChanceStau === "edit") {
            let editparams = {
              ...this.formData,
            };
            if (editparams.facilityNo) {
              this.facilityList.forEach((zzfac) => {
                if (zzfac.facilityNo === editparams.facilityNo) {
                  editparams.facilityName = zzfac.facilityName;
                }
              });
            }
            if (editparams.unitNo) {
              this.unitList.forEach((unitem) => {
                if (unitem.unitNo === editparams.unitNo) {
                  editparams.unitName = unitem.unitName;
                }
              });
            }
            if (this.formData.batchList) {
              editparams.farmingTypeNo = this.batchfarmtypeid;
              editparams.batchNo = this.formData.batchList.value;
              delete editparams.batchList;
            }
            // if (this.formData.standardNo) {
            //   editparams.noSpecification = true
            // } else {
            //   editparams.noSpecification = false
            // }
            editparams.yieldDate = this.dateToFormat(editparams.yieldDate);
            // console.log(this.formData.grade)
            if (this.formData.grade === 0) {
              editparams.grade = "优";
            } else if (this.formData.grade === 1) {
              editparams.grade = "良";
            } else {
              editparams.grade = "差";
            }
            // console.log(editparams,'批量修改'); return
            nowpagereq.editlist(editparams).then((res) => {
              if (res.code === 1) {
                this.getTableDataList();
                this.$message.success("修改成功");
                this.closeDialog();
                this.reset();
                this.$refs[formData].resetFields();
              } else {
                this.$message.error("修改失败");
              }
            });
          }
        } else {
          return false;
        }
      });
    },
    openDialog(type) {
      this.dialogFormVisible = true;
      this.dialogTitle = type === "add" ? "新增" : "编辑";
      this.nowChanceStau = type;
    },
    closeDialog() {
      this.dialogFormVisible = false;
      this.dialogTitle = null;
      this.nowChanceStau = "";
      this.batchList = [];
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
